<!-- 批量审核表单 -->

<template>
    <el-dialog
      :model-value="dialogFormVisible"
      :destroy-on-close="true"
      title="提现审核"
      width="450px"
      @close="emits('closeDialog')"
    >
      <el-form
        ref="dialogFormRef"
        :model="dialogForm"
        :rules="rules"
        :label-width="formLabelWidth"
      >
        <el-form-item label="状态" prop="status">
          <el-select v-model="dialogForm.status" placeholder="状态">
            <el-option label="审核中" value="0" />
            <el-option label="审核通过" value="1" />
            <el-option label="审核失败" value="2" />
            <el-option label="已打款" value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="理由">
          <!-- remark -->
          <!-- fail_reason -->
          <el-input
            v-model="dialogForm.remark"
            :rows="2"
            type="textarea"
            placeholder="请输入理由"
          />
        </el-form-item>
  
        <el-form-item label="id" style="display: none">
          <el-input v-model="dialogForm.id_list" disabled />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="emits('cancel')">取消</el-button>
          <el-button
            type="primary"
            @click="submit(dialogForm)"
            :loading="btnLoading"
          >
            提交
          </el-button>
        </span>
      </template>
    </el-dialog>
  </template>
  <script setup>
  import { ref } from "vue";
  const dialogFormRef = ref(null);
  
  defineProps({
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
    dialogForm: {
      type: Object,
      default: {
        id_list: "",
        status: "",
        remark:""
       
      },
    },
    btnLoading: {
      type: Boolean,
      default: false,
    },
  });
  const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);
  
  const formLabelWidth = "120px";
  // 校验
  const rules = {
    status: [{ required: true, message: "请选择一个状态", trigger: "blur" }],
  };
  // 提交
  const submit = (dialogForm) => {
    dialogFormRef.value
      .validate()
      .then(async () => {
        try {
          const param = Object.assign({}, dialogForm);
          param.status = Number(param.status);
          param.id_list  = [...new Set(param.id_list)] 
          emits("submitForm", param);
        } catch (error) {
          console.log(error);
        }
      })
      .catch((error) => {
        console.log(error);
      });
  };
  </script>
  